<!DOCTYPE html>
<html xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org">
<head th:include="/include/commonHeader::commonHeader('排班授权编辑')"></head>
<body>
<div class="wrapper wrapper-content">
    <div class="col-sm-12">
        <form class="form-horizontal m-t" id="exampleForm">
            <input id="pCode" name="pCode" th:value="${scheduleAuthority.pCode}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">人员：</label>
                <div class="col-sm-7">
                    <input id="fullName" name="fullName" th:value="${scheduleAuthority.fullName}" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">公司授权：</label>
                <div class="col-sm-7">
                    <input id="iTechName" name="iTechName" th:value="${scheduleAuthority.iTechName}" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">
                <div class="col-xs-3 form-label-v">
                <label><font style="color:red;">*</font>排班授权：</label>
            </div>
                <div class="col-xs-8">
                    <select id="techNoZ" name="techNoZ" th:value="${scheduleAuthority.techNoZ}"></select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">月飞限制：</label>
                <div class="col-sm-8">
                    <input id="limitOfMonth" name="limitOfMonth" th:value="${scheduleAuthority.limitOfMonth}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <div class="col-xs-3 form-label-v">
                    <label><font style="color:red;">*</font>能否备份：</label>
                </div>
                <div class="col-xs-8">
                    <select id="isBackup" name="isBackup" th:value="${scheduleAuthority.isBackup}">
                    </select>
                </div>
            </div>
            <div class="form-group">
                <div class="col-xs-3 form-label-v">
                    <label><font style="color:red;">*</font>能否过夜：</label>
                </div>
                <div class="col-xs-8">
                    <select id="isOvernight" name="isOvernight" th:value="${scheduleAuthority.isOvernight}">
                    </select>
                </div>
            </div>
            <div class="form-group">
                <div class="text-center">
                    <button id="btn_save" onclick="save()" type="button" class="btn btn-primary">提交</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script src="/plugins/bootstrapValidator/js/bootstrapValidator.min.js"></script>
<script src="/plugins/bootstrapValidator/js/language/zh_CN.js"></script>
<!-- 自定义js -->
<script th:inline="javascript">
    var prefix = "/scheduleAuthority";
    var dutyCode = "[[${dutyCode}]]".substr(1,1);
    $(function () {
        //初始化下列框
        select2InitForData("#techNoZ", "/select2/getTechNoZ.do?techType="+dutyCode, [[${scheduleAuthority.techNoZ}]], null, false, null);
        select2InitForData("#isBackup", "/select2/getYandN.do", [[${scheduleAuthority.isBackup}]], null, false, null);
        select2InitForData("#isOvernight", "/select2/getYandN.do", [[${scheduleAuthority.isOvernight}]], null, false, null);
    });
    //保存
    function save() {
        $.ajax({
            cache: true,
            type: "POST",
            url: prefix + "/update.do",
            data: $('#exampleForm').serialize(),
            async: false,
            error: function (request) {
                parent.layer.alert("Connection error");
            },
            success: function (data) {
                if (data.code == 0) {
                    parent.layer.msg("操作成功");
                    parent.reload();
                    var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                    parent.layer.close(index);
                } else {
                    parent.layer.alert(data.msg);
                }
            }
        });
    }

    //初始化验证规则
    function initValidator() {
        $('#exampleForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                pCode1: {
                    message: '人员A不能为空',
                    validators: {
                        notEmpty: {
                            message: '此项不能为空'
                        },
                        different: {
                            field: 'pCode2',
                            message: '不能同人员B相同'
                        }
                    }
                },
                pCode2: {
                    message: '人员B不能为空',
                    validators: {
                        notEmpty: {
                            message: '此项不能为空'
                        },
                        different: {
                            field: 'pCode1',
                            message: '不能同人员A相同'
                        }
                    }
                }
            }
        });
    }
</script>
</body>
</html>
